/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Animation.Animations;

import Scenery.BaseSprite;
import main.DumbMath;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.MotionPathListener;
import com.jme3.cinematic.events.MotionTrack;
import com.jme3.math.FastMath;
import com.jme3.math.Quaternion;
import com.jme3.math.Vector3f;
import Animation.Animation;
import Animation.Animation;
import Animation.Animation;
import Scenery.BaseCharacter;
import Scenery.BaseSprite;
import Scenery.BaseSprite;

/*
 * 
 * @author: Ziden
 * 
 */

public class FootRashin extends Animation {
    
    // original positions
    Vector3f rfoot;
    Vector3f lfoot;
    
    private int legStep = 0;
    private float legSpeed = 0.05f;
    private float maxLegStep = 0.2f;
    private float minLegStep = -0.2f;
    private float legAngle = 0f;
    private float inverseLegAngle = 0f;
    private float ammountToMove = ((-1*minLegStep)+maxLegStep) / legSpeed;
    private int framesPerStep = 10;
    private int numberOfSteps = 2;
    
    public FootRashin(BaseCharacter dude, int frames) {
        super(dude, frames);
        storedValues = 2;
        buildAnimation();
    }
   
    @Override
    public String getName() {
        return "StepTurn";
    }

    @Override
    public void gotoInitialState() {
        framesPerStep = 10;
        numberOfSteps = -1;
        animationBody.getLfoot().setLocalTranslation(lfoot);
        animationBody.getRfoot().setLocalTranslation(rfoot);
        legAngle = 0;
        inverseLegAngle = 0;
        legStep =0;
        frame = 0;
        canceled = false;
    }

    @Override
    public void saveInitialState() {
        rfoot = animationBody.getRfoot().getLocalTranslation().clone();
        lfoot = animationBody.getLfoot().getLocalTranslation().clone();
    }

    @Override
    protected void buildFrame() {
        if (legStep == 0) {
            if (legAngle < maxLegStep) {
                legAngle += legSpeed;
                inverseLegAngle -=legSpeed;
                animationFrames[frame][0] = legAngle;
                animationFrames[frame][1] = inverseLegAngle;
            } else {
                legStep = 1;
            }
        } else if (legStep == 1) {
            if (legAngle > minLegStep) {
                legAngle -= legSpeed;
                inverseLegAngle += legSpeed;
                animationFrames[frame][0] = legAngle;
                animationFrames[frame][1] = inverseLegAngle;
            } else {
                legStep = 0;
            }
        }
    }

    @Override
    public void performFrame() {
         animationBody.getLfoot().setLocalTranslation(animationFrames[frame][0], lfoot.y ,lfoot.z );
         animationBody.getRfoot().setLocalTranslation(animationFrames[frame][1], rfoot.y ,rfoot.z );
         if(frame==maxFrame-1)
             this.canceled = true;
    }

    @Override
    protected float getCicleRunTime() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
